package com.gome.oa.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author: tang li
 * @date: 2016年8月13日
 * @desc:
 *
 */
public class PrepareActionListner implements ActionListener {

	private JTextField textFilePath;
	
	private JFrame mainFrame;

	public PrepareActionListner(JTextField textFilePath, JFrame mainFrame) {
		super();
		this.textFilePath = textFilePath;
		this.mainFrame = mainFrame;
	}

	@Override
	public void actionPerformed(ActionEvent paramActionEvent) {
		JFileChooser fileChooser = new JFileChooser();
		fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		fileChooser.setFileFilter(new FileFilter() {
			
			@Override
			public String getDescription() {
				return "*.xls,*.xlsx";
			}
			
			@Override
			public boolean accept(File file) {
				String name = file.getName();  
		        return name.toLowerCase().endsWith(".xls")
		        		|| name.toLowerCase().endsWith(".xlsx"); 
			}
		});
		fileChooser.showDialog(mainFrame, "选择");
		File file = fileChooser.getSelectedFile();
		if (file != null && file.isFile()) {
			textFilePath.setText(file.getAbsolutePath());
		}
	}

}
